package com.woniuxy.main.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

import com.woniuxy.main.pojo.Coach;
import com.woniuxy.main.pojo.Student_coach;

import com.woniuxy.main.pojo.User;
import com.woniuxy.main.pojo.Vi_coachOrder_studentInfo;
import com.woniuxy.main.provider.CoachProvider;


public interface CoachMapper {
	
	//  查询教练收费
	@Select("select price from coach where cid = #{cid}")
	public int searchPriceByCid(int cid);
	
	//查询教练收费
	@Select("select price from coach inner join `order` on coach.cid=order.cid where oid=#{oid}")
	public double coachPrice(int oid);
	
	//根据oid查询uid、money
	@Select("select user.uid,money,payPwd from `order` inner join coach on order.cid=coach.cid inner join user on coach.uid=user.uid where order.oid=#{oid}")
	public User getUser(int oid);
	
	//查询全部学员教练中间表信息
	@Select("select sc.sid,sc.cid,sc.createdate,sc.updatedate,sc.`status` "
			+ "from student_coach sc inner join student s on sc.sid = s.sid where sc.cid = #{currentCid}")
	public List<Student_coach> findAllContract(int currentCid);
	
	//根据教练uid查询当前所有签约学员的信息
	@Select("select * from vi_coachOrder_studentInfo where cid=#{cid} order by sid limit #{page},8")
	public List<Vi_coachOrder_studentInfo> showMyStudentList(Map<String,Object> request);
	
	//根据教练uid查询当前签约学员的总数
	@Select("select COUNT(*) from vi_coachOrder_studentInfo where uid=#{uid}")
	public int myStudentTotalCount(int uid);
	
	//修改状态
	@Update("update student_coach set updateDate=#{updateDate},status=#{status} where cid=#{cid} and sid=#{sid}")
	public int alterStatus(Student_coach sc);

	//教练更新个人信息
	@UpdateProvider(type=CoachProvider.class,method="coachUpdate")
	public int updateCoach(Coach coach);

	//创建教练
	@Insert("insert into coach(uid) values(#{uid})")
	public int insertCoach(int uid);
	
	//根据UID查询教练信息
	@Select("select * from coach where uid=#{uid}")
	public Coach selectByUid(int uid);
	
	//管理员添加教练账户插入教练表
	@Insert("insert into coach(uid,cname,cage,csex,publicLevel) values(#{uid},#{cname},#{cage},#{csex},#{publicLevel})")
	public int adminAdd(Coach coach);
	
	//根据uid查询教练cid
	@Select("select cid from coach where uid=#{uid}")
	public int findCidByUid(int uid);
}
